package com.vote.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.vote.dao.util.HibernateDao;
import com.vote.dao.util.Page;
import com.vote.entity.QuestionInfo;
import com.vote.util.VoteConstants;


@Repository
public class QuestionInfoDao extends HibernateDao<QuestionInfo, Long> {
	
	private static Logger logger = LoggerFactory.getLogger(QuestionInfoDao.class);
	
	public Page<QuestionInfo> listByPage(Page<QuestionInfo> page, DetachedCriteria detach) {
		return this.findPage(page, detach);
	}	
	public List<QuestionInfo> listQuestionInfo(String part){
		String hql="";
		if(VoteConstants.QUESTION_PART_A.equals(part)){
			hql="select q from QuestionInfo q where q.partA=? and q.status=? order by q.sequenceA";	
		}else{
			hql="select q from QuestionInfo q where q.partB=? and q.status=? order by q.sequenceB";
		}		
		return this.createQuery(hql,part,VoteConstants.COMMON_STATUS_ENABLE).list();
	}	
}